package test.aop;


import java.util.Timer;
import java.util.TimerTask;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;



@Aspect
@Component
@Scope("prototype")
public class MenuRepositoryAOP {
	private String a = null;
	private Object message = null;
	 public MenuRepositoryAOP() {
		// TODO Auto-generated constructor stub
		 System.out.println("aop init");
		 a = "I am new ";
	}
	// 最靠近(..)的为方法名,靠近.*(..))的为类名或者接口名,如上例的JoinPointObjP2.*(..))
	/**
	 * 任意公共方法的执行： execution(public * *(..)) 任何一个以“set”开始的方法的执行： execution(*
	 * set*(..)) AccountService 接口的任意方法的执行： execution(*
	 * com.xyz.service.AccountService.*(..)) 定义在service包里的任意方法的执行： execution(*
	 * com.xyz.service.*.*(..)) 定义在service包和所有子包里的任意类的任意方法的执行： execution(*
	 * com.xyz.service..*.*(..)) 定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行：
	 * execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))") >
	 * 最靠近(..)的为方法名,靠近.*(..))的为类名或者接口名,如上例的JoinPointObjP2.*(..))
	 * 
	 * 
	 */
	@Pointcut("execution(* test.controller.*.*(..))")
	public void pointcut() {
	}
	@Around(value = "pointcut()")
	public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
		Thread current = Thread.currentThread();
		Long id = current.getId();
		System.out.println("before: "+id+"--"+a);
		
		time();
		
		
		
		
		Object object = joinPoint.proceed();
		a = "I am old";
		System.out.println("after: "+id+"--"+a);
		// return new ExceptionDomain("can not in");
		return object;

	}
	
	public void update(Object object){
		
	}
	
	private void time(){
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			
			@Override
			public void run() {
				message = "hello";
				
			}
		},2000);
	}
	
	
	
}
